//! $Id$
//!
//! @file    Injector.h
//! @author  Johan Andersson <skagget77@gmail.com>
//! @date    Fri Oct 02 21:35 2009
//! @ingroup IoCpp
//!

#if !defined(IOCPP_INJECTOR_H)
#define IOCPP_INJECTOR_H

#include "IoCpp/Detail/ResolverCache.h"

#include <string>

namespace IoCpp
{
   //!
   //! @author  Johan Andersson <skagget77@gmail.com>
   //! @date    Fri Oct 02 21:35 2009
   //! @ingroup IoCpp
   //!
   //! The Injector class.
   //!
   class IOCPP_API Injector
   {
   public :
      //!
      //! Creates a new instance of the Injector class.
      //!
      //! @param cache The container's ResolverCache.
      //!
      Injector( const Detail::ResolverCache& cache );

      //!
      //! Injects an instance of the specified type.
      //!
      //! @return An instance of the specified type.
      //!
      template<class T1>
      T1 Inject() const;

      //!
      //! Injects an instance of the specified type. When the type matches more
      //! than one instance the name parameter is used to resolve which one to
      //! inject.
      //!
      //! @param  name A user defined name to resolve potential ambiguities.
      //!
      //! @return An instance of the specified type.
      //!
      template<class T1>
      T1 Inject( const std::string& name ) const;

   private :
      // Prevent copying.
      Injector( const Injector& );
      Injector& operator=( const Injector& );

      const Detail::ResolverCache& cache;
   };


   template<class T1>
   T1 Injector::Inject() const {
      return cache.Resolve<T1>();
   }


   template<class T1>
   T1 Injector::Inject( const std::string& name ) const {
      return cache.Resolve<T1>(name);
   }
}


#endif   // IOCPP_INJECTOR_H
